;(function() {
		init_parsley();
		//同步会员信息
		$("#btn-sync").click(function(){
			var card_no=$("#card_no").val();
			if(card_no==null||(card_no.length<5)){
				toastr["error"]("卡号错误");
				return false;
			}else{
				var csharp=window.external;
				loading();
				var memberstr=csharp.GetMemberInfo(card_no);
				var result=jQuery.parseJSON(memberstr);
				console.log(result);
				close_loading();
				 if(result.Flag){
				 	result=result.Data;
				 	$("#member_id").val(result.MemberID);
				 	$("#contract_id").val(result.ContractID);
				 	$("#mobile").val(result.Mobile);
				 	$("#name").val(result.MemberName);
				 	$("#start_date").val(result.StartDate);
				 	$("#end_date").val(result.EndDate);
				 	$("#contract_status").val(result.ContractStatus);
				 	$("#membership_type").val(result.MembershipType);
				 	$("#surplus_num").val(result.SurplusNum);
				 	toastr["success"]("成功");
				 }else{
				 	toastr["error"](result.Msg,"错误提示");
				 }
				 return false;
			}
		})
		
	   	$("#form-submit").click(function(){
	   		var flag=$('#validate-form').parsley('validate' );
	   		if(flag){
	   			var type=$("#membership_type").val();
	   			if(!(type==1||type==2||type==3)){
	   				toastr['error']("请先同步安科会员数据");
	   				return false;
	   			}
	   			$.post(
	   				"/admin/member/sync",
	   				$("#validate-form").serialize(),
	   				function(data){
			      		if(data.flag){
			      			$("#myModal").modal("hide");
			      			toastr['success']("操作成功！", ''); 
			      			$("#myform #btn-advanced-refresh").trigger("click");// 刷新页面
			      		}else{
			      		 	toastr['error'](data.msg,"操作失败！"); 
			      		}
	   				}
	   			);
	   		}
	   	})
	   	
})();
